package com.apobates.forum.toro.test.core;

import com.apobates.forum.toro.BatchQueryFace;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ArticleInitData {
    protected static HashMap<Long,Article> amap = new HashMap<>();
    protected static HashMap<Integer,ArticleSection> smap = new HashMap<>();
    protected static HashMap<Integer,Author> mmap= new HashMap<>();
    //
    protected static Function<String,Author> authorSelectFun = (authorId) -> mmap.get(Integer.valueOf(authorId));
    protected static Function<String,ArticleSection> sectionSelectFun = (sectionId) -> smap.get(Integer.valueOf(sectionId));

    protected static Article ar5;
    //
    static{
        Author a1 = new Author(1, "subpu", "admin@subpu.com", "1.jpg", 100101000, false);
        mmap.put(1, a1);
        Author a2 = new Author(2, "lisa", "lisa@subpu.com", "2.jpg", 100101001, true);
        mmap.put(2, a2);
        Author a3 = new Author(3, "yana", "admin@subpu.com", "3.jpg", 100101002, false);
        mmap.put(3, a3);
        Author a4 = new Author(4, "tina", "admin@subpu.com", "4.jpg", 100101003, false);
        mmap.put(4, a4);
        Author a5 = new Author(5, "Reyes", "admin@subpu.com", "5.jpg", 100101004, true);
        mmap.put(5, a5);
        Author a6 = new Author(6, "Marry", "admin@subpu.com", "6.jpg", 100101005, true);
        mmap.put(6, a6);
        Author a7 = new Author(7, "Rolla", "admin@subpu.com", "7.jpg", 100101006, false);
        mmap.put(7, a7);
        //
        ArticleSection as1 = new ArticleSection(10, "Java", "DevLang", "dev", "/dev/java");
        smap.put(10, as1);
        ArticleSection as2 = new ArticleSection(11, "Python", "DevLang", "dev", "/dev/python");
        smap.put(11, as2);
        ArticleSection as3 = new ArticleSection(12, "Eclipse", "DevIDE", 2, "ide", "/ide/eclipse");
        smap.put(12, as3);
        ArticleSection as4 = new ArticleSection(13, "NetBeans", "DevIDE", 2, "ide", "/dev/netbeans");
        smap.put(13, as4);
        ArticleSection as5 = new ArticleSection(14, "IntelliJ IDEA", "DevIDE", 2, "ide", "/dev/ideaJ");
        smap.put(14, as5);
        ArticleSection as6 = new ArticleSection(15, "Tomcat", "Container", 3, "http", "/container/tomcat");
        smap.put(15, as6);
        ArticleSection as7 = new ArticleSection(16, "JBoss", "Container", 3,"http", "/container/JBoss");
        smap.put(16, as7);
        //
        Article ar1 = new Article(11011L,
                "中国从服务大国迈向服务强国",
                "2022年中国国际服务贸易交易会于8月31日至9月5日在北京举行。服贸会十年，也是我国服务贸易快速发展的十年",
                "大国,中国",
                "11011A01", 10, 7);
        amap.put(11011L, ar1);
        Article ar2 = new Article(11012L,
                "俄气无限期关闭北溪-1天然气管道",
                "9月2日，俄罗斯天然气工业股份公司发布消息称，由于发现多处设备故障，“北溪-1”天然气管道将完全停止输气",
                "俄气,天然气,北溪",
                "11011A02", 11, 6);
        amap.put(11012L, ar2);
        Article ar3 = new Article(11013L,
                "成都女子疫情期囤冰箱",
                "成都一女子晒出疫情期间自家“囤冰箱”的视频。女子表示：一共是三套房子，有11台冰箱。疫情期间，有这么多冰箱不",
                "成都,冰箱,女子,疫情",
                "11011A03", 10, 6);
        amap.put(11013L, ar3);
        Article ar4 = new Article(11014L,
                "神十四航天员首次出舱看点解析",
                "9月2日，神舟十四号乘组完成首次出舱活动。出舱舱门更大、安全绳更长、仪表与照明分系统更智能等，是神舟十四号航天员首",
                "出舱,神舟",
                "11011A04", 16, 5);
        amap.put(11014L, ar4);
        ar5 = new Article(11015L,
                "印度超越英国成为第五大经济体",
                "根据国际货币基金组织的数据，以美元计价，从去年四季度开始，印度GDP就已经超越了英国",
                "印度,英国,国际货币基金组织",
                "11011B01", 15, 5);
        amap.put(11015L, ar5);
        Article ar6 = new Article(11016L,
                "男生暑假送外卖俩月赚1万7",
                "山东齐河的大二男生赵春阳利用暑假打工送外卖,60天一共送出了3474单,赚了一万七千多,不仅交了新学期的学费,接下来的生活费也解决了",
                "暑假,外卖,打工",
                "11011C01", 14, 1);
        amap.put(11016L, ar6);
    }

    protected static Collection<Author> queryAuthorFace(Collection<String> authorIds){
        Set<Integer> collect = authorIds.stream().map(Integer::valueOf).collect(Collectors.toSet());
        return mmap.entrySet().stream().filter(entry->collect.contains(entry.getKey())).map(Map.Entry::getValue).collect(Collectors.toSet());
    }

    protected static Collection<ArticleSection> querySectionFace(Collection<String> sectionIds){
        Set<Integer> collect = sectionIds.stream().map(Integer::valueOf).collect(Collectors.toSet());
        return smap.entrySet().stream().filter(entry->collect.contains(entry.getKey())).map(Map.Entry::getValue).collect(Collectors.toSet());
    }

    protected static Collection<Article> queryArticle(List<Long> articleIds){
        return amap.entrySet().stream().filter(entry->articleIds.contains(entry.getKey())).map(Map.Entry::getValue).collect(Collectors.toSet());
    }
}
